#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, V, l, p[N], pre[N * 10];
struct Car {
	int l, r;
	friend bool operator < (Car a, Car b) {
		if (a.l != b.l)
			return a.l < b.l;
		return a.r < b.r;
	}
} a[N];
int Calc(int l, int r) {
	if (l > r)
		return 0;
	return pre[r] - (l == 0 ? 0 : pre[l - 1]);
}
void Solve() {
	scanf("%d%d%d%d", &n, &m, &l, &V);
	for (int i = 1; i <= n; i++) {
		a[i].l = a[i].r = -1;
		int d, v, A;
		scanf("%d%d%d", &d, &v, &A);
		if (A == 0) {
			if (v > V)
				a[i].l = d, a[i].r = l;
		}
		else if (A < 0) {
			if (v <= V)
				continue;
			A = -A;
			int k = (v * v - V * V - 1) / (A * 2);
			if (k >= 0)
				a[i].l = d, a[i].r = min(l, d + k);
		}
		else {
			int k = (V * V - v * v) / (A * 2) + 1;
			if (d + k <= l)
				a[i].l = d + max(0, k), a[i].r = l;
		}
	}
	memset(pre, 0, sizeof pre);
	for (int i = 1; i <= m; i++)
		scanf("%d", p + i), pre[p[i]]++;
	for (int i = 1; i <= l; i++)
		pre[i] += pre[i - 1];
	int ans1 = 0;
	for (int i = 1; i <= n; i++)
		if (a[i].l != -1) {
			if (Calc(a[i].l, a[i].r) > 0)
				ans1++;
			else
				a[i].l = a[i].r = -1;
		}
	printf("%d ", ans1);
	sort(a + 1, a + n + 1);
	int cur = 1;
	while (cur <= n and a[cur].l == -1)
		cur++;
	int mn = INT_MAX, ans = 0;
	for (int i = cur; i <= n; i++) {
		if (Calc(a[i].l, min(a[i].r, mn)) == 0)
			ans++, mn = a[i].r;
		mn = min(mn, a[i].r);
	}
	printf("%d\n", m - ans - (mn != INT_MAX));
}
signed main() {
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	int t;
	scanf("%d", &t);
	while (t--)
		Solve();
	return 0;
}